package entitys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class SolicitudCotizacion implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -172440150575231426L;
	private int idSolCot;
	private List<ItemSolicitudCotizacion> items;
	private Cotizacion cotizacion;
	private Cliente cliente;
	
	public SolicitudCotizacion() {
		items = new ArrayList<ItemSolicitudCotizacion>();
	}
	
	@Id
	@Column(name = "idSolCot", nullable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public int getIdSolCot() {
		return idSolCot;
	}

	public void setIdSolCot(int idSolCot) {
		this.idSolCot = idSolCot;
	}
	
	@OneToMany(cascade=CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    @JoinColumn(name = "idSolCot")
	public List<ItemSolicitudCotizacion> getItems() {
		return items;
	}

	public void setItems(List<ItemSolicitudCotizacion> items) {
		this.items = items;
	}
	
	@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
	public Cotizacion getCotizacion() {
		return cotizacion;
	}

	public void setCotizacion(Cotizacion cotizacion) {
		this.cotizacion = cotizacion;
	}
	
	@ManyToOne
	@LazyCollection(LazyCollectionOption.FALSE)
	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idSolCot;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SolicitudCotizacion other = (SolicitudCotizacion) obj;
		if (idSolCot != other.idSolCot)
			return false;
		return true;
	}

	public void addItem(ItemSolicitudCotizacion oItem) {
		items.add(oItem);
	}
	
}
